package com.hdsx.restful.glzt.structure.ql.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.ql.bean.DoubleValueName;
import com.hdsx.restful.glzt.structure.ql.bean.IntValueName;
import com.hdsx.restful.glzt.structure.ql.bean.Ql;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.glzt.structure.ql.mapper.QlMapper;
import com.hdsx.restful.glzt.structure.ql.service.QlServer;
import com.hdsx.restful.util.Dao;


@Service
public class QlServerImpl extends BaseOpearte<Ql> implements QlServer {

	public QlServerImpl() {
		super("GIS_QL");
	}
	@Resource(name="qlMapper")
	private QlMapper mapper; 
	@Override
	public List<Ql> getListByLxbm(String lxbm,int begin,int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Ql> list=mapper.selectListByLxbm(parameter);

		return list;
	}
	@Override
	public int queryQlCountByLxbm(String lxbm) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		return mapper.countByLxbm(parameter);
	}
	@Override
	public int queryCount(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		return mapper.selectCount(parameter);
	}
	@Override
	public List<Ql> queryList(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name,int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Ql> lists=mapper.selectList(parameter);
		return lists;
	}
	@Override
	public Ql getOne(String qldm) {
		return mapper.queryOne(qldm);
	}
	@Override
	public List<Ql> getListByXzqhbm(String xzqhbm, int begin, int end) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByXzqhbm(parameter);
	}
	@Override
	public int queryQlCountXzqhbm(String xzqhbm) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		return mapper.countByXzqhbm(parameter);
	}
	@Override
	public List<Ql> countQlkjfldmByXzqhbm(String xzqhbm) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		return mapper.countQlkjfldmByXzqhbm(xzqhbm);
	}
	@Override
	public List<Ql> countQlkjfldmByLxbm(String lxbm) {
		return mapper.countQlkjfldmByLxbm(lxbm);
	}
	@Override
	public List<Dao> getShapeById(String id) {
		 Ql ql = mapper.getShapeById(id);
		 if(ql==null) return null;
		 IGeometry shape=selectShape("ID='"+ql.getId()+"'");
		 ql.setShape(shape);
		 List<Dao> lists=new ArrayList<Dao>();
		 lists.add(new Dao("桥梁名称",ql.getQlmc(),ql.getPtx(),ql.getPty()));
		 lists.add(new Dao("桥梁编码",ql.getQldm()));
		 lists.add(new Dao("所在路线",ql.getLxbm()));
		 lists.add(new Dao("中心桩号",ql.getQlzxzh()));
		 lists.add(new Dao("跨径分类",ql.getQlkjfldm()));
		return lists;
	}
	@Override
	public StatisticalResult countByParameter(Map<String,Object> map) {
		List<IntValueName> seriesData = mapper.countTotalByParameter(map);
		List<DoubleValueName> seriesLengthData = mapper.countLengthByParameter(map);
		List<String> legendData = mapper.selectClassify(map);
		StatisticalResult sr = new StatisticalResult();
		sr.setChartsText("桥梁统计");
		sr.setSeriesData(seriesData);
		sr.setSeriesLengthData(seriesLengthData);
		sr.setLegendData(legendData);
		return sr;
	}
	/**
	 * 行政等级查询节点 H G S X
	 * 
	 * @return
	 */
	@Override
	public List<Znode> qlNode() {
		List<Znode> qlNode = mapper.qlNode();
		return qlNode;
	}
	/**
	 * 分类细节
	 */
	@Override
	public List<Ql> detail(Map<String, Object> map){
		return mapper.detail(map);
	}
	@Override
	public int countDetail(Map<String, Object> map) {
		return  mapper.countDetail(map);
	}
	
	 @Override
	 public int countTotal(Map<String, Object> map){
		 return mapper.countTotal(map);
	 }
	 
	 @Override
	 public List<Ql> listAll(String lxbm,String xzqhbm,String sxxfx,Double qdzh,
			Double zdzh,String name) {
		return mapper.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
	 }
	 @Override
	public Ql queryById(String id) {
			return mapper.selectById(id);
	}
	 
		@Override
		public List<String> selectName(String name){
			return mapper.selectName(name);
		}

}
